<template>
  <!-- 图生视频 -->
  <div class="son-page-container" :style="{ backgroundImage: `url(${website_bg_url})` }">
    <el-container class="main-container">
      <el-header height="10vh" class="header-container">
        <MyHeader />
      </el-header>
      <el-main>
        <el-row :gutter="20">
          <el-col :span="4">
            <div class="spacer">
              <div class="content-nav">
                <div class="nav-right">
                  <button class="nav-btn" @click="handleProductLibrary">
                    <el-icon class="btn-icon">
                      <VideoCamera />
                    </el-icon>
                    成品库
                  </button>
                </div>
              </div>
            </div>
            <div class="area-container menu-container area-container-sec">
              <div class="sub-menu-title">生成视频</div>
              <div v-for="menu in menuList" :key="menu.id" class="menu-item">
                <div class="menu-title" @click="toggleSubMenu(menu)">
                  <span>{{ menu.name }}</span>
                  <i v-if="menu.children" :class="['arrow', menu.isOpen ? 'arrow-down' : 'arrow-right']"></i>
                </div>
                <div v-if="menu.children && menu.isOpen" class="sub-menu">
                  <div v-for="subMenu in menu.children" :key="subMenu.id" class="sub-menu-item"
                    :class="{ active: selectedSubMenu === subMenu.id }" @click="selectSubMenu(subMenu)">
                    {{ subMenu.name }}
                  </div>
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="20">
            <div class="right-area">
                <div class="right-header">
                  <div class="header-title">为您生成</div>
                  <div class="header-subtitle">AI生成，仅供参考，您对该内容的使用应严格遵循国家相关法律法规的规定</div>
                </div>
                <div class="right-main">
                  <PlainGenerate v-if="plainGenerateIds.includes(selectedSubMenu)" />
                  <WudongrenxiangGenerate v-else-if="12 == selectedSubMenu" />
                  <YuedongchangyanGenerate v-else-if="13 == selectedSubMenu" />
                  <LingdongbobaoGenerate v-else-if="14 == selectedSubMenu" />
                  <BiaoqingbaoGenerate v-else-if="15 == selectedSubMenu" />
                  <MultiImgGenerate v-else-if="16 == selectedSubMenu" />
                  <KouxingtihuanGenerate v-else-if="21 == selectedSubMenu" />
                  <RepaintGenerate v-else-if="31 == selectedSubMenu" />
                </div>
            </div>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import axiosUtil from '../../axios-util/axios-util'
import { ArrowDown, UploadFilled } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import utils from '../../utils/utils';
import PlainGenerate from './image2videosub/PlainGenerate.vue';
import WudongrenxiangGenerate from './image2videosub/WudongrenxiangGenerate.vue';
import YuedongchangyanGenerate from './image2videosub/YuedongchangyanGenerate.vue';
import LingdongbobaoGenerate from './image2videosub/LingdongbobaoGenerate.vue';
import BiaoqingbaoGenerate from './image2videosub/BiaoqingbaoGenerate.vue';
import MultiImgGenerate from './image2videosub/MultiImgGenerate.vue';
import KouxingtihuanGenerate from './image2videosub/KouxingtihuanGenerate.vue';
import RepaintGenerate from './image2videosub/RepaintGenerate.vue';
import MyHeader from '../common/MyHeader.vue';

const router = useRouter()
//主题控制light  dark
const theme = utils.getTheme();
// 网站背景图
const website_bg_url = ref('')
// 网站logo
const website_logo = ref('')

interface SubMenuItem {
  id: number
  pid: number
  name: string
}

interface MenuItem {
  id: number
  pid: number
  name: string
  children?: SubMenuItem[]
  isOpen?: boolean
}

const menuList = ref<MenuItem[]>([
  {
    id: 1,
    pid: 0,
    name: '图生视频',
    isOpen: true,
    children: [
      {
        id: 11,
        pid: 1,
        name: '默认风格',
      }, {
        id: 12,
        pid: 1,
        name: '舞动人像',
      }, {
        id: 13,
        pid: 1,
        name: '悦动唱演',
      }, {
        id: 14,
        pid: 1,
        name: '灵动播报',
      }, {
        id: 15,
        pid: 1,
        name: '表情包'
      }, {
        id: 16,
        pid: 1,
        name: '多图参考'
      }
    ]
  }, {
    id: 2,
    pid: 0,
    name: '口型替换',
    children: [
      {
        id: 21,
        pid: 2,
        name: '默认'
      }
    ]
  }, {
    id: 3,
    pid: 0,
    name: '视频风格重绘',
    children: [
      {
        id: 31,
        pid: 3,
        name: '默认'
      }
    ]
  }
])

const typeMap = {
  '11': 'iv_default',
  '12': 'iv_wudongrenxiang',
  '13': 'yuedongchangyan',
  '14': 'iv_lingdongbobao',
  '15': 'iv_biaoqingbao',
  '16': 'iv_duotucankao'
}

const selectedSubMenu = ref<number | null>(11)

const plainGenerateIds = [11];

const toggleSubMenu = (menu: MenuItem) => {
  // 关闭其他所有菜单
  menuList.value.forEach(item => {
    if (item.id !== menu.id) {
      item.isOpen = false
    }
  })
  // 切换当前菜单
  menu.isOpen = !menu.isOpen
}

const selectSubMenu = (subMenu: SubMenuItem) => {
  selectedSubMenu.value = subMenu.id
}

const handleProductLibrary = () => {
  router.push('/videoWarehouse?id=12')
}

onMounted(() => {
  initWebsiteBgUrl()
  document.body.classList.remove('login-page')
})

//读取配置，获取网站背景图和网站logo
const initWebsiteBgUrl = async () => {
  const response = await axiosUtil.post('api/pc/site/get_agent_config', {})
  if (response.data.code === 0 && response.data.data) {
    website_bg_url.value = import.meta.env.VITE_APP_SERVER + response.data.data.website_bg || ''
    website_logo.value = import.meta.env.VITE_APP_SERVER + response.data.data.website_logo || ''
  }
}
</script>

<style scoped>
.son-page-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.main-container {
  height: 100vh;
  width: 100%;
  backdrop-filter: blur(5px);
}

.header-container {
  padding: 0;
  width: 100%;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"');
  backdrop-filter: blur(10px);
  border-bottom: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
  box-shadow: 0 4px 6px v-bind('theme === "light" ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.2)"');
}

.son-frame-nav-title {
  padding: 20px 40px;
  color: #fff;
  font-size: 1.4rem;
  font-weight: bold;
  text-shadow: 0 2px 8px #003366, 0 0 16px #00aaff;
  letter-spacing: 6px;
}

.spacer {
  height: 80px;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  /* padding: 0 20px; */
  /* margin-top: 3vh; */
}

.content-nav {
  height: 100%;
  width: 100%;
  display: flex;
  /* justify-content: flex-end; */
  align-items: center;
  /* padding: 0 20px; */
  background: transparent;
  border: none;
  box-shadow: none;
}

.nav-right {
  display: flex;
  align-items: start;
  width: 100%;
  height: 100%;
  padding-bottom: 12px;
}

.nav-btn {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  padding: 12px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 100%;
}

.nav-btn:hover {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.3)"');
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.3)"');
  box-shadow: 0 0 10px v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.3)"');
}

.btn-icon {
  font-size: 16px;
}

/* .content-nav {
  height: 60px;
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0 20px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.nav-right {
  display: flex;
  align-items: center;
}

.nav-btn {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.3)"');
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.4)"');
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
}

.nav-btn:hover {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.4)"');
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(0, 0, 0, 0.5)"');
  box-shadow: 0 0 10px v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.3)"');
} */

.el-main {
  padding: 20px;
  height: 85vh;
  overflow-x: hidden;
}

.el-row {
  height: 100%;
  margin: 0 !important;
}

.el-col {
  height: 100%;
}

.area-container-sec {
  height: calc(100% - 80px) !important;
}

.area-container {
  height: 100%;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  backdrop-filter: blur(10px);
  border-radius: 12px;
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  box-shadow: 0 4px 6px v-bind('theme === "light" ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.2)"');
  transition: all 0.3s ease;
  padding: 15px;
}

/* .area-container:hover {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.3)"');
  box-shadow: 0 6px 12px v-bind('theme === "light" ? "rgba(0, 0, 0, 0.15)" : "rgba(255, 255, 255, 0.25)"');
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.3)"');
} */

.menu-container {
  overflow-y: auto;
}

.right-area {
  border-radius: 12px;
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  box-shadow: 0 4px 6px v-bind('theme === "light" ? "rgba(0, 0, 0, 0.1)" : "rgba(0, 0, 0, 0.2)"');
  transition: all 0.3s ease;
  padding: 15px;
  min-height: 70vh;
  height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-container::-webkit-scrollbar {
  width: 6px;
}

.menu-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.menu-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
}

.menu-item {
  margin-bottom: 15px;
}

.menu-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  border-radius: 4px;
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  cursor: pointer;
  transition: all 0.3s ease;
}

.menu-title:hover {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.3)"');
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(255, 255, 255, 0.3)"');
  box-shadow: 0 0 10px v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
}

.arrow {
  width: 0;
  height: 0;
  border-style: solid;
  transition: all 0.3s ease;
}

.arrow-right {
  border-width: 6px 0 6px 8px;
  border-color: transparent transparent transparent #fff;
}

.arrow-down {
  border-width: 8px 6px 0 6px;
  border-color: #fff transparent transparent transparent;
}

.sub-menu {
  margin-top: 5px;
  margin-left: 15px;
}

.sub-menu-item {
  padding: 10px 15px;
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.3s ease;
  margin-bottom: 5px;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
}

.sub-menu-item:hover {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.15)" : "rgba(0, 0, 0, 0.15)"');
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(0, 0, 0, 0.3)"');
}

.sub-menu-item.active {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.4)" : "rgba(0, 0, 0, 0.4)"');
  box-shadow: 0 0 10px v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
}

.center-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 20px;
}

.center-top {
  flex: 1;
  min-height: 0;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"');
  border-radius: 4px;
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
  padding: 15px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.center-bottom {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"');
  border-radius: 4px;
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
  padding: 15px;
  box-sizing: border-box;
}

.image-section {
  display: flex;
  flex-direction: column;
  height: 180px;
}



.count-section {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.section-content {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"');
  border-radius: 4px;
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
  padding: 15px;
}

.generate-content {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.generate-row {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}

.count-input {
  width: 120px;
}

.count-input :deep(.el-input-number__decrease),
.count-input :deep(.el-input-number__increase) {
  background: v-bind('theme === "light" ? "rgba(0, 102, 204, 0.4)" : "rgba(0, 102, 204, 0.5)"');
  border-color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.3)" : "rgba(0, 204, 255, 0.4)"');
  color: #fff;
}

.count-input :deep(.el-input-number__decrease:hover),
.count-input :deep(.el-input-number__increase:hover) {
  background: v-bind('theme === "light" ? "rgba(0, 102, 204, 0.6)" : "rgba(0, 102, 204, 0.7)"');
  border-color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.5)" : "rgba(0, 204, 255, 0.6)"');
}

.count-input :deep(.el-input__wrapper) {
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"');
  box-shadow: 0 0 0 1px v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(0, 0, 0, 0.3)"');
}

.count-input :deep(.el-input__wrapper:hover) {
  box-shadow: 0 0 0 1px v-bind('theme === "light" ? "rgba(255, 255, 255, 0.5)" : "rgba(0, 0, 0, 0.5)"');
}

.count-input :deep(.el-input__inner) {
  color: #fff;
}

.generate-btn {
  width: 120px;
  background: v-bind('theme === "light" ? "rgba(0, 102, 204, 0.6)" : "rgba(0, 102, 204, 0.7)"') !important;
  border-color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.4)" : "rgba(0, 204, 255, 0.5)"') !important;
  color: #fff !important;
  transition: all 0.3s ease;
  margin-left: 0;
}

.generate-btn:hover {
  background: v-bind('theme === "light" ? "rgba(0, 102, 204, 0.8)" : "rgba(0, 102, 204, 0.9)"') !important;
  border-color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.6)" : "rgba(0, 204, 255, 0.7)"') !important;
  box-shadow: 0 0 15px v-bind('theme === "light" ? "rgba(0, 204, 255, 0.3)" : "rgba(0, 204, 255, 0.4)"');
}

.upload-section {
  margin-top: 0;
}

.upload-component {
  width: 100%;
}

.upload-component :deep(.el-upload) {
  width: 100%;
}

.upload-component :deep(.el-upload-dragger) {
  width: 100%;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"');
  border: 1px dashed v-bind('theme === "light" ? "rgba(255, 255, 255, 0.3)" : "rgba(0, 0, 0, 0.3)"');
  border-radius: 4px;
}

.upload-component :deep(.el-upload-dragger:hover) {
  border-color: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.6)" : "rgba(0, 0, 0, 0.6)"');
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.15)" : "rgba(0, 0, 0, 0.15)"');
}

.upload-component :deep(.el-icon--upload) {
  margin: 20px 0 16px;
  font-size: 48px;
  color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.6)" : "rgba(0, 204, 255, 0.7)"');
}

.upload-component :deep(.el-upload__text) {
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  font-size: 14px;
  text-align: center;
  margin: 0 0 16px;
}

.upload-component :deep(.el-upload__text em) {
  color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.8)" : "rgba(0, 204, 255, 0.9)"');
  font-style: normal;
}

.upload-component :deep(.el-upload__tip) {
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.6)" : "rgba(255, 255, 255, 0.6)"');
  font-size: 12px;
  text-align: center;
}

.right-content {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.right-header {
  height: 10%;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.header-title {
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  font-size: 20px;
  font-weight: bold;
}

.header-subtitle {
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.6)" : "rgba(255, 255, 255, 0.6)"');
  font-size: 12px;
}

.right-main {
  flex: 1;
  overflow-y: auto;
  background: v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(255, 255, 255, 0.2)"');
  border-radius: 4px;
  border: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.2)"');
}

.right-footer {
  height: 10%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.publish-btn {
  background: v-bind('theme === "light" ? "rgba(0, 102, 204, 0.6)" : "rgba(0, 102, 204, 0.7)"') !important;
  border-color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.4)" : "rgba(0, 204, 255, 0.5)"') !important;
  color: #fff !important;
  transition: all 0.3s ease;
}

.publish-btn:hover {
  background: v-bind('theme === "light" ? "rgba(0, 102, 204, 0.8)" : "rgba(0, 102, 204, 0.9)"') !important;
  border-color: v-bind('theme === "light" ? "rgba(0, 204, 255, 0.6)" : "rgba(0, 204, 255, 0.7)"') !important;
  box-shadow: 0 0 15px v-bind('theme === "light" ? "rgba(0, 204, 255, 0.3)" : "rgba(0, 204, 255, 0.4)"');
}

/* .spacer {
  height: 5vh;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 0 20px;
  margin-top: 3vh;
} */

.spacer-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sub-menu-title {
  color: v-bind('theme === "light" ? "rgba(0, 0, 0, 0.8)" : "#fff"');
  font-size: 16px;
  font-weight: 500;
  padding: 10px 0;
  margin-bottom: 10px;
  text-align: left;
  border-bottom: 1px solid v-bind('theme === "light" ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.4)"');
}
</style>

<style>
/* 隐藏全局背景图 */
body::before {
  display: none !important;
}

/* 优化Son页面背景图和滚动条 */
html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: hidden;
}

body {
  background: url(../../assets/main/背景.png) no-repeat center center;
  background-size: cover;
}
</style>
